﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;

namespace MimiDouban.Test
{
    public class BugReport
    {
        private static readonly string Version = "1.3.8 alpha";
        public static void Show(string message)
        {
            MessageBox.Show(message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

        public static void ShowReport(string message, Exception e)
        {
            if (MessageBox.Show(message + " 是否发送错误报告到给kellyxiepei？",
                "错误报告", MessageBoxButtons.OKCancel, MessageBoxIcon.Question
                  ) == DialogResult.OK)
            {
                try
                {
                    string time = DateTime.Now.ToString() + "." + DateTime.Now.Millisecond;
                    MailMessage myMail = new MailMessage();
                    myMail.From = new MailAddress("mimi_bug_reporter@163.com");
                    myMail.To.Add(new MailAddress("kellyxiepei@gmail.com"));
                    myMail.Subject = "MimiDoubanV"+Version+"错误报告"; 
                    myMail.Priority = MailPriority.Low;
                    myMail.Body = "错误:" + time + "-" + message + "\r\n"
                        + e.GetType().ToString() + ":" + e.Message + "\r\n" + e.StackTrace;

                    SmtpClient client = new SmtpClient("smtp.163.com");
                    client.DeliveryMethod = SmtpDeliveryMethod.Network;
                    client.Credentials = new System.Net.NetworkCredential("mimi_bug_reporter", "xiewangyi123");
                    //client.EnableSsl = true;
                    client.Send(myMail);
                    MessageBox.Show("发送成功，谢谢您的支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex) 
                {
                    TestLog.getInstance().error("发送邮件失败", ex);
                }
            };
        }
    }
}
